package com.orion.config;

import org.springframework.security.web.authentication.WebAuthenticationDetails;

import javax.servlet.http.HttpServletRequest;

/**
 * 类似于UserDetails类给我们提供了用户详细信息一样，WebAuthenticationDetails则为我们提供了登录请求的用户的信息
 * （也就是申请登录的用户的username和password信息），springsecurity默认只验证用户的username和password信息，
 * 所以我们如果想实现验证码登录，需要重写WebAuthenticationDetails类，使其能通过HttpServletRequest获取到用户输入的验证码的信息。
 *
 * @author Administrator
 * @date 2021/9/11
 */
public class CustomWebAuthenticationDetails extends WebAuthenticationDetails {

    //验证码
    private String verifyCode;

    /**
     * Records the remote address and will also set the session Id if a session already
     * exists (it won't create one).
     *
     * @param request that the authentication request was received from
     */
    public CustomWebAuthenticationDetails(HttpServletRequest request) {
        super(request);
        verifyCode = request.getParameter("verifyCode");
    }

    public String getVerifyCode() {
        return verifyCode;
    }

    public void setVerifyCode(String verifyCode) {
        this.verifyCode = verifyCode;
    }

    @Override
    public String toString() {
        return "CustomWebAuthenticationDetails{" +
                "verifyCode='" + verifyCode + '\'' +
                '}';
    }
}
